package com.protonail.core.licenses;

import com.protonail.core.licenses.license.License;
import com.protonail.core.licenses.license.LicenseType;

import java.time.Instant;

/**
 * Created by shenli on 2017/6/21.
 */
public class LicenseDeserializer {

    public static  LicenseDeserializer INSTANCE;

    public final DeserializerResult deserialize(String licenseText) {
        ExtractorResult extractorResult = LicenseExtractor.INSTANCE.extractLicense(licenseText);
        DeserializerResult result;
        if(extractorResult.isExtracted()) {
            byte[] var10001 = extractorResult.getEncryptedLicense();
            result = this.deserialize(var10001);
        } else {
            result = new DeserializerResult(extractorResult.getMessage());
        }
        return result;
    }

    public final DeserializerResult deserialize( byte[] encryptedLicense) {
        License result = new License();
        result.setOwner(System.getProperty("user.name"));
        result.setExpiresAt(Instant.MAX);
        result.setType(LicenseType.Enterprise);
        result.setProductUid("keylord");
        result.setUid("1111");
        return new DeserializerResult("License is deserialized.", result);
    }

    private LicenseDeserializer() {
        INSTANCE = (LicenseDeserializer)this;

    }

    static {
        new LicenseDeserializer();
    }
}
